package com.xyoto.community.controller;

import com.xyoto.community.dto.DeleteDynamicCommentDTO;
import com.xyoto.community.dto.DeleteQuestionCommentDTO;
import com.xyoto.community.dto.GetQuestionCommentDTO;
import com.xyoto.community.dto.SaveQuestionCommentDTO;
import com.xyoto.community.service.QuestionCommentService;
import com.xyoto.community.utils.PageUtils;
import com.xyoto.community.utils.Result;
import com.xyoto.community.vo.QuestionCommentsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 问答评论controller
 */
//@RestController
@Api(tags = "问答评论")
@RequestMapping("/topic")
public class QuestionCommentController {

    @Autowired
    private QuestionCommentService questionCommentService;

    /**
     * 新增问答评论
     * @return
     */
    @ApiOperation("新增问答评论")
    @PostMapping("/saveQuestionComment")
    public Result saveQuestionComment(@Valid @RequestBody SaveQuestionCommentDTO saveQuestionCommentDTO){
        return questionCommentService.saveQuestionComment(saveQuestionCommentDTO);
    }

    /**
     * 根据问答id分页查询问答评论列表
     *
     * @param queryDto 分页查询问答评论列表DTO
     *
     * @return Result<PageUtils<QuestionCommentsVo>>
     */
    @ApiOperation(value = "根据问答id分页查询问答评论列表Web接口", notes = "根据问答id分页查询问答评论列表Web接口")
    @GetMapping("/getQuestionCommentsList")
    public Result<PageUtils<QuestionCommentsVo>> getQuestionCommentsListById(
            @Validated GetQuestionCommentDTO queryDto){
        return questionCommentService.getQuestionCommentsListById(queryDto);
    }

    /**
     * 删除问答评论
     * @param deleteQuestionCommentDTO 问答评论id
     * @return
     */
    @ApiOperation("删除问答评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "questionCommentId" ,value = "问答评论id" ,required = true)
    })
    @DeleteMapping("/deleteQuestionComment")
    public Result removeQuestionComment(@RequestBody DeleteQuestionCommentDTO deleteQuestionCommentDTO){
        return questionCommentService.removeQuestionComment(deleteQuestionCommentDTO.getQuestionCommentId());
    }
}
